package com.goldsprite.microhorigame.ecs.fsms.states;

import com.goldsprite.gameframeworks.log.Debug;

public class EntityDeathState extends EntityState {
	private boolean completedDestory = true;

	@Override
	public boolean canEnter() {
		return fsm.getInputs().getKeyDeath();//触发死亡指令
	}

	@Override
	public boolean canExit() {
		return !fsm.getProps().isDead();//血量高于0了
	}

	@Override
	public void enter() {
		fsm.getInputs().setKeyDeath(false);
		fsm.getAnims().playAnim("Death", true);
		Debug.logT("GFsm", "实体%s进入死亡.", fsm.getName());
	}

	@Override
	public void running() {
		if(fsm.getAnims().isAnimCompleted()) {
			if(completedDestory)
				fsm.getGObject().destroy();
		}
	}

	public EntityDeathState noDestory() {
		completedDestory = true;
		return this;
	}

}
